﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CosAging;
using CosAging.Windows;
using Org.BouncyCastle.Asn1.Crmf;
using Org.BouncyCastle.Crmf;
using Timer = System.Timers.Timer;

namespace CosAging.View
{
    /// <summary>
    /// SystemMonitor.xaml 的交互逻辑
    /// </summary>
    public partial class SystemMonitor : UserControl
    {

        public static double PixelCoefficient = 1;
        public int CurrentID;
        public Timer BeginTimer = new Timer(); public Timer ReadTimer = new Timer();
        public Timer UpdateTimer1 = new Timer();
        public static string NameSelected;

        public SystemMonitor()
        {
            //PublicClass.计时起点();
            InitializeComponent();
            Class_Initialize();
            //ProgressBegin();
            //PublicClass.计时终点();
            //PublicClass.Logger.Info(PublicClass.时间差);

        }
        private void ProgressBegin()
        {

            //Thread thread = new Thread(new ThreadStart(() =>
            //{
            //    for (int i = 0; i <= 100; i++)
            //    {
            //        this.progressBar1.Dispatcher.BeginInvoke((ThreadStart)delegate { this.progressBar1.Value = i; });
            //        Thread.Sleep(100);
            //    }

            //}));
            //thread.Start();
        }
        private void Class_Initialize()
        {
            //try
            //{


            //for (int i = 0; i < 20; i++)
            //{
            //    for (int j = 0; j < 4; j++)
            //    {
            //        Grid GD = new Grid();


            //        ColumnDefinition c1 = new ColumnDefinition();
            //        c1.Width = new GridLength(1, GridUnitType.Star);
            //        ColumnDefinition c2 = new ColumnDefinition();
            //        c2.Width = new GridLength(1, GridUnitType.Star);
            //        ColumnDefinition c3 = new ColumnDefinition();
            //        c3.Width = new GridLength(1, GridUnitType.Star);
            //        ColumnDefinition c4 = new ColumnDefinition();
            //        c4.Width = new GridLength(1, GridUnitType.Star);
            //        ColumnDefinition c5 = new ColumnDefinition();
            //        c5.Width = new GridLength(0, GridUnitType.Star);
            //        GD.ColumnDefinitions.Add(c1);
            //        GD.ColumnDefinitions.Add(c2);
            //        GD.ColumnDefinitions.Add(c3);
            //        GD.ColumnDefinitions.Add(c4);
            //        GD.ColumnDefinitions.Add(c5);
            //        string Nrow = i.ToString("00");
            //        string Ncol = j.ToString("00"); ;
            //        Style GD_style = new Style();
            //        GD_style = (Style)FindResource("GridStyle");
            //        GD.Style = GD_style;
            //        GD.Name = "GDZLAN" + Nrow + Ncol;

            //        int NSDT = j + i * 4;
            //        for (int l = 0; l < 4; l++)
            //        {
            //            if (l != 2)
            //            {
            //                Label LB = new Label();
            //                LB.Background = new SolidColorBrush(Colors.Transparent);

            //                LB.FontWeight = FontWeights.Bold;
            //                LB.HorizontalAlignment = HorizontalAlignment.Stretch;
            //                LB.VerticalAlignment = VerticalAlignment.Stretch;
            //                LB.HorizontalContentAlignment = HorizontalAlignment.Center;
            //                LB.VerticalContentAlignment = VerticalAlignment.Center;
            //                //LB.Height = 30 * PixelCoefficient;
            //                //LB.Width = 80 * PixelCoefficient;
            //                LB.FontSize = 17 * PixelCoefficient;
            //                LB.Margin = new Thickness(0, 0, 0, 0);
            //                LB.FontFamily = new FontFamily("宋体");
            //                //准备Binding
            //                Binding binding1 = new Binding();//创建Binding实例
            //                binding1.Source = PublicClass.CDSDTint[NSDT];//指定数据源

            //                Binding binding2 = new Binding();//创建Binding实例
            //                binding2.Source = PublicClass.CDSDTint[NSDT];//指定数据源
            //                binding2.Path = new PropertyPath("Local_NameE");//设备名

            //                Binding binding3 = new Binding();//创建Binding实例
            //                binding3.Source = PublicClass.CDSDTint[NSDT];//指定数据源
            //                binding3.Path = new PropertyPath("TimeText_Foreground");//颜色

            //                if (l == 0)
            //                {
            //                    LB.Foreground = new SolidColorBrush(Colors.Black);
            //                    LB.MouseDoubleClick += LB_MouseDoubleClick;
            //                    binding1.Path = new PropertyPath("Local_NameE");//设备名 
            //                    BindingOperations.SetBinding(LB, Label.ForegroundProperty, binding3);//使用binding实例将数据源与目标关联起来
            //                }
            //                else if (l == 1)
            //                {
            //                    LB.Foreground = new SolidColorBrush(Colors.Black);
            //                    LB.MouseDoubleClick += LB_MouseDoubleClick;
            //                    binding1.Path = new PropertyPath("TestName");//测试项 
            //                }
            //                else if (l == 3)
            //                {
            //                    LB.MouseDoubleClick += LB_MouseDoubleClick;
            //                    binding1.Path = new PropertyPath("TimeText");//剩余时间 
            //                                                                 //BindingOperations.SetBinding(LB, Label.ForegroundProperty, binding3);//使用binding实例将数据源与目标关联起来
            //                }
            //                //使用Binding 连接数据源与Bingding目标
            //                BindingOperations.SetBinding(LB, Label.ContentProperty, binding1);//使用binding实例将数据源与目标关联起来
            //                BindingOperations.SetBinding(LB, Label.NameProperty, binding2);//使用binding实例将数据源与目标关联起来
            //                                                                               //BindingOperations.SetBinding(LB, Label.ForegroundProperty, binding3);//使用binding实例将数据源与目标关联起来
            //                GD.Children.Add(LB);
            //                Grid.SetRow(LB, 0);
            //                Grid.SetColumn(LB, l);
            //                Grid.SetColumnSpan(LB, 1);
            //                //PB.HorizontalAlignment = HorizontalAlignment.Stretch;
            //            }
            //            else
            //            {
            //                ProgressBar PB = new ProgressBar();
            //                PB.Value = 0;
            //                //PB.Background = new SolidColorBrush(Colors.Transparent);
            //                //PB.Foreground = new SolidColorBrush(Colors.Black);
            //                //PB.FontWeight = FontWeights.Bold;
            //                //PB.VerticalAlignment = VerticalAlignment.Bottom;
            //                //PB.HorizontalAlignment = HorizontalAlignment.Left;
            //                //PB.HorizontalContentAlignment = HorizontalAlignment.Center;
            //                //PB.VerticalContentAlignment = VerticalAlignment.Center;
            //                Style PB_style = new Style();
            //                PB_style = (Style)FindResource("ProgressBar01");
            //                PB.Style = PB_style;
            //                PB.FontSize = 17 * PixelCoefficient;
            //                PB.Margin = new Thickness(0, 0, 0, 0);
            //                PB.FontFamily = new FontFamily("宋体");
            //                PB.MouseDoubleClick += PB_MouseDoubleClick;
            //                Binding binding1 = new Binding();//创建Binding实例
            //                binding1.Source = PublicClass.CDSDTint[NSDT];//指定数据源                           
            //                binding1.Path = new PropertyPath("PBValue");//剩余时间

            //                Binding binding2 = new Binding();//创建Binding实例
            //                binding2.Source = PublicClass.CDSDTint[NSDT];//指定数据源
            //                binding2.Path = new PropertyPath("Local_NameE");//设备名
            //                                                                //使用Binding 连接数据源与Bingding目标
            //                BindingOperations.SetBinding(PB, ProgressBar.ValueProperty, binding1);//使用binding实例将数据源与目标关联起来
            //                BindingOperations.SetBinding(PB, Label.NameProperty, binding2);//使用binding实例将数据源与目标关联起来
            //                GD.Children.Add(PB);
            //                Grid.SetRow(PB, 0);
            //                Grid.SetColumn(PB, l);
            //                Grid.SetColumnSpan(PB, 1);
            //            }
            //        }
            //        this.MainGrid.Children.Add(GD);
            //        //放在1，1的位置
            //        Grid.SetRow(GD, i);
            //        Grid.SetColumn(GD, j);
            //        Grid.SetColumnSpan(GD, 1);
            //    }
            //}

            //    SQL.MysqlTempDataRead();

            //    //if (App.Dic.ContainsKey("SplashWindow"))
            //    //{
            //    //    SplashWindow sw = App.Dic["SplashWindow"] as SplashWindow;///在PublicClass有定义程序开始先打开SplashWindow窗口
            //    //    sw.Dispatcher.Invoke((Action)(() => sw.Close()));//在sw的线程上关闭SplashWindow

            //    //}
            //}
            //catch (Exception ex )
            //{
            //    MessageBox.Show(ex.Message);
            //    PublicClass.NLOGex(ex);
            //}

        }

        private void LB_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            //Label LB = e.Source as Label;
            //String NM = LB.Name;

            System.Windows.Controls.Label CLabel = (System.Windows.Controls.Label)sender;
            NameSelected= CLabel.Name;
            CameraWindow W1 = new CameraWindow();
            double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
            double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
            double windowWidth = W1.Width;
            double windowHeight = W1.Height;
            W1.Left = (screenWidth / 2) - (windowWidth / 2);
            W1.Top = (screenHeight / 2) - (windowHeight / 2);
            W1.ShowDialog();

        }
        private void PB_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {

            //System.Windows.Controls.ProgressBar CProgressBar = (System.Windows.Controls.ProgressBar)sender;
            //NameSelected = CProgressBar.Name;
            //CameraWindow W1 = new CameraWindow();
            //double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
            //double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
            //double windowWidth = W1.Width;
            //double windowHeight = W1.Height;
            //W1.Left = (screenWidth / 2) - (windowWidth / 2);
            //W1.Top = (screenHeight / 2) - (windowHeight / 2);
            //W1.ShowDialog();

        }        
    }
}
